package com.flyqiu.flow.model.entity.ru;

import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.flyqiu.common.mybaits.plus.type.MyBaitsFastJson2ObjectHandler;
import com.flyqiu.common.user.FlyQiuUser;
import lombok.Data;

import java.time.LocalDateTime;

@Data
@TableName(ProcRuIdentityLink.TABLE_NAME)
public class ProcRuIdentityLink {
    public static final String TABLE_NAME = "FLY_FLOW_RU_IDENTITY_LINK";
    @TableId(value = "ID_", type = IdType.ASSIGN_UUID)
    private String id;
    @TableField("PROC_INST_ID_")
    private String procInstId;
    @TableField("ACT_ID_")
    private String actId;
    @TableField("ACT_INST_ID_")
    private String actInstId;
    @TableField("TYPE_")
    private String type;
    @TableField("USER_ID_")
    private String userId;
    @TableField("USER_NICK_NAME_")
    private String userNickName;
    @TableField("USER_KEY_")
    private String userKey;
    @TableField("USER_UNIQUE_KEY_")
    private String userUniqueKey;
    @TableField(value = "USER_ATTR_", typeHandler = MyBaitsFastJson2ObjectHandler.class)
    private JSONObject userAttr;
    @TableField("TENANT_ID_")
    private String tenantId;
    @TableField("CREATE_TIME_")
    private LocalDateTime createTime;

    public static ProcRuIdentityLink create(FlyQiuUser ownerUser, String procInstId, String actId, String actInstId , String type) {
        ProcRuIdentityLink result=create(ownerUser, type, ownerUser.getTenantId());
        result.setProcInstId(procInstId);
        result.setActId(actId);
        result.setActInstId(actInstId);
        return result;
    }


    public static ProcRuIdentityLink create(FlyQiuUser ownerUser, String type, String tenantId) {
        ProcRuIdentityLink link = new ProcRuIdentityLink();
        link.tenantId = tenantId;
        link.userId = ownerUser.getId();
        link.userNickName = ownerUser.getNickName();
        link.userKey = ownerUser.getUserType();
        link.userAttr = ownerUser.getUserAttr();
        link.userUniqueKey = ownerUser.getUniqueKey();
        link.type = type;
        return link;
    }
}
